1. /* slfdkmul.cpp by K.Tsuru */
  2. // function ID = 219 DRADIX, BRADIX
  3. /*************************************************
  4. SLong and SInteger classes
  5. z = (huge x) * (huge y) for x.Size() >= y.Size()
  6. It provides the Karatsuba's multiplication.
  7. ***************************************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. void SLong::KaratsubaHHMult(const SLong& x, const SLong& y, SLong& z){
  12. uint xfig = ceilpow2(x.Head()+1), yfig = ceilpow2(y.Head()+1), k, fms;
  13. fms = x.FFTMaxArraySize()/2;
  14. if( (xfig <= fms) && (yfig <= fms) ){
  15. z = x*y;
  16. return;
  17. }
  18. SLong p, q, t;
  19. p.CutDown(ENABLE);
  20. p = x; q = y;
  21. p.CutDown(p.POP);
  22. p.CutDown(DISABLE);
  23. if( (xfig > fms) && (fms > yfig) ) yfig = fms;
  24. uint dN = xfig/yfig; // number of division
  25. #ifndef NDEBUG
  26. assert(dN); // |x| >= |y|
  27. #endif
  28. if(dN == 1){
  29. KHHMult(p, q, z); return;
  30. }
  31. // divided p into dN parts a[dN].
  32. SLong* a = new SLong[dN];
  33. for(k = 0; k < dN ; k++){
  34. SLCutOut(a[k], p, k*yfig, yfig);
  35. }
  36. KHHMult(a[0], q, z);
  37. for(k = 1; k < dN ; k++){
  38. KHHMult(a[k], q, t);
  39. z += t.MultPowRdx(k*yfig);
  40. }
  41. delete [] a;
  42. }

slfdkmul.cpp : last modifiled at 2017/03/04 21:12:22(1,141 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).